{layout name="common/base" }
<div class="layui-form layuimini-form">

    <input type="text" hidden value="<?php echo $product_id;?>" name="product_id"><!-- 商品id -->

    <div class="layui-form-item">
        <label class="layui-form-label required">题目</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="题目不能为空" placeholder="请输入题目" value="" class="layui-input">
        </div>
    </div>
    <div id="optiondiv">
    <div class="layui-form-item">
        <label class="layui-form-label">选项：</label>
        <div class="layui-input-block">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="content[0]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
                <label class="layui-form-label">分数</label>
                <div class="layui-input-inline">
                    <input type="number" name="score[0]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" onclick="deletediv(this);">删除</a>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项：</label>
        <div class="layui-input-block">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="content[1]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
                <label class="layui-form-label">分数</label>
                <div class="layui-input-inline">
                    <input type="number" name="score[1]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" onclick="deletediv(this);">删除</a>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选项：</label>
        <div class="layui-input-block">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="content[2]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
                <label class="layui-form-label">分数</label>
                <div class="layui-input-inline">
                    <input type="number" name="score[2]" placeholder="请输入选项内容" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" onclick="deletediv(this);">删除</a>
            </div>
        </div>
    </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="data-add-option-btn">
                <i class="layui-icon">&#xe608;</i> 添加一个选项
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="__PUBLIC__/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="__PUBLIC__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/commons.js" charset="utf-8"></script>
<script>
    var url = '/admin/question/add';
    add_edit(url);
    /*添加选项*/
    var options = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    var optioni = 2;//数组从0开始，进入页面已经创建好三个
    layui.use(['form'], function () {
        var $ = layui.jquery;
        $("#data-add-option-btn").on("click", function () {
            optioni++;
            $("#optiondiv").append(
                '<div class="layui-form-item">'+
                    //'<label class="layui-form-label">'+ options[optioni] +'选项：</label>'+
                '<label class="layui-form-label">选项：</label>'+
                    '<div class="layui-input-block">'+
                        '<div class="layui-inline">'+
                            '<div class="layui-input-inline">'+
                                '<input type="text" name="content['+optioni+']" placeholder="请输入选项内容" value="" class="layui-input">'+
                            '</div>'+
                            '<label class="layui-form-label">分数</label>'+
                            '<div class="layui-input-inline">'+
                                '<input type="number" name="score['+optioni+']" placeholder="请输入选项内容" value="" class="layui-input">'+
                            '</div>'+
                        '</div>'+
                        '<div class="layui-inline">'+
                            '<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" onclick="deletediv(this);">删除</a>'+
                        '</div>'+
                    '</div>'+
                '</div>'
            );
        });
    });

    function deletediv(a) {
        optioni--;
        //$('#optiondiv .layui-form-item').last().remove()
        $(a).parent().parent().parent().remove();
    }
</script>
